import { BotApi, XinghanApi, plugin } from '../../model/api/api.js'
import { sql_run } from '../api.js'
export class xhemonUser extends plugin {
    constructor() {
        super({
            name: 'Yunzai_Bot_xinhan_richang',
            dsc: '星瀚日常模块',
            event: 'message',
            priority: 6000,
            rule: [
                {
                    reg: '^#星瀚注册.*$',
                    fnc: 'xinghanRegister'
                }
                // ,
                // {
                //     reg: '^.*$',
                //     fnc: 'xinghanDay'
                // }
            ]
        })
    }
    async xinghanDay(e) {
        if (await register(e.user_id)) {
            let now_Time = new Date().getTime();
            let today = await redis.get('xinghan:day:' + e.user_id + ':' + now_Time);
            console.log('111' + today + '111')
            if (!today) {
                e.reply("null")
            }
        }
        return
    }

    async xinghanRegister(e) {
        if (await register(e.user_id)) {
            e.reply("注册失败，您已注册！")
        } else {
            let nowTime = new Date().getTime();
            let sql2 = `insert into user values (${e.user_id},0,0,1,${nowTime},"")`
            await sql_run(sql2);
            e.reply('注册成功！现在您可以获取积分了！')
        }
        return;
    }
}

export async function register(qq) {
    let sql1 = `select * from user where qq=${qq};`
    let log = await sql_run(sql1)
    if (log != undefined && log != "undefined" && log.length > 2) {
        return true;
    } else {
        return false;
    }
}